import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";
import { AccountListGetResultModel } from "@/api/demo/model/systemModel";

const { createConfirm } = useMessage();

enum Api {
  list = '/report1/yingshou/list',
  list2 = '/report/reconciliationReport/list',
  list3 = '/report3/qianshou/list',
  save='/report3/reconciliationReport/add',
  edit='/report3/reconciliationReport/edit',
  deleteOne = '/report3/reconciliationReport/delete',
  deleteBatch = '/report3/reconciliationReport/deleteBatch',
  importExcel = '/report3/reconciliationReport/importExcel',
  exportXls = '/report3/reconciliationReport/exportXls',
  // list2 = '/mock/wuye/wuye/list',
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = async (params) => {
  try {
    const response = await defHttp.get({ url: Api.list, params });
    return response;
  } catch (error) {
    // 处理错误
    console.error('Error fetching data:', error);
    throw error;
  }
};
export const total = () => defHttp.get({ url: '/report1/yingshou/total' });

// export const list = (params) => defHttp.get({ url: Api.list, params });
// export const list2 = (params) => defHttp.get({ url: Api.list2, params });
// export const list3 = (params) => defHttp.get({ url: Api.list3, params });
//mock接口
// export const list = (params: Api.list2) => defHttp.get<AccountListGetResultModel>({ url: Api.list2, params });

/**
 * 下拉搜索框接口
 */
const optionUrl = 'http://localhost:3100/jeecgboot/sys/sysDepart/queryMyDeptTreeListOrgType3';
export const optionslist = () => defHttp.get({ url: optionUrl });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}
